
module.exports = function(grunt) {

    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-requirejs');

    // Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            js: {
                options: {
                    banner: '/*! <%= pkg.author %> */\n',
                    footer: '/*! the end */',
                    mangle:true,
                    beautify:false,
                    preserveComments:false,
                    enclose:{window:'window',requirejs:'requirejs'}
                },
                files: [{
                    'build/dist/js/loginMain.js':['dist/js/loginEntry.js']
                },{
                    'build/dist/js/main.js':['dist/js/entry.js']
                }]
            },
            //jsx:{
            //    options: {
            //        mangle:false
            //    },
            //    files:[
            //        {
            //            expand:true,
            //            cwd:'./',//js目录下
            //            src:'plugins/**/*.js',//所有js文件
            //            dest: 'build/'//输出到此目录下
            //        }
            //    ]
            //}

        },
        cssmin: {
            target: {
                files: [{
                    'build/dist/css/all.css': ['dist/css/AdminLTE.css','./dist/css/skins/skin-green.min.css','dist/css/global.css']
                }]
            }
        },
        clean:{
            'build':['build/*']
        },
        copy: {
            main: {
                files: [
                    {expand: true, src: ['bootstrap/**'], dest: 'build/'},
                    {expand: true, src: ['plugins/**','!plugins/**/**.md','!plugins/**/**.txt','!plugins/**/examples/**'], dest: 'build/'},
                    {expand: true, src: ['simdata/**'], dest: 'build/'},
                    {expand: true, src: ['wwwroot/**'], dest: 'build/'},
                    {expand: true, src: ['*.html','!login_old.html'], dest: 'build/'},
                    {expand: true, src: ['dist/img/**'], dest: 'build/'},
                    {expand: true, src: ['src/**'], dest: 'build/'}
                ]
            }
        },
        watch: {
            scripts: {
                files: ['dist/**','bootstrap/**','plugins/**','simdata/**','wwwroot/**','*'],
                options: {
                    interrupt: true,
                    debounceDelay: 10000,
                    reload: true
                },
                tasks: ['clean','uglify','cssmin','copy']
            }
        },
        jshint: {
            options: {
                //# 大括号包裹
                curly: true,
                //# 对于简单类型，使用===和!==，而不是==和!=
                eqeqeq: true,
                //# 对于首字母大写的函数（声明的类），强制使用new
                newcap: true,
                //# 禁用arguments.caller和arguments.callee
                noarg: true,
                //# 对于属性使用aaa.bbb而不是aaa['bbb']
                sub: true,
                //# 查找所有未定义变量
                undef: true,
                //# 查找类似与if(a = 0)这样的代码
                boss: true,
                //# 指定运行环境为node.js
                node: false,
                //# 指定运行环境为浏览器
                browser: true,

                globals: {
                    '$': false,
                    'console': false,
                    'requirejs': false,
                    '_': false,
                    'jQuery': false,
                    'USEN': false,
                    'U': false,
                    'toastr': false,
                    'BootstrapMenu': false
                }
            },
            files: {
                src: [
                    'dist/js/*.js',
                    '!dist/js/demo.js',
                    '!dist/js/app.js',
                    '!dist/js/app.min.js'
                ]
            }

        },
        requirejs: {
            compile: {
                options: {
                    baseUrl: "./",
                    mainConfigFile: "./dist/js/main.js",
                    // name: "./dist/js/entry.js",
                    optimize: 'uglify',
                    include: [ 'app','helper','core' ],
                    excludeShallow: ['config'],
                    out: "build/dist/js/all.js"
                }
            }
        }
    });

    // Default task(s).
    grunt.registerTask('default', ['clean','uglify','cssmin','copy', 'requirejs']);
};